package cn.edu.scau.cmi.longyuanjun.compositePattern;

import java.util.ArrayList;
import java.util.Iterator;

public class Composite extends ComputerParts{
	private String description = "";
	private double price = 0;
	
	private ArrayList<ComputerParts> parts;
	
	public Composite() {
		parts = new ArrayList<ComputerParts>();
	}
	
	public String getDescription() {
		return description;
	}
	
	public double getPrice() {
		int len = parts.size();
		for (int i = 0; i < len; i++) {
			ComputerParts part = parts.get(i);
			price = price + part.getPrice();
		}
		
		return price;
	}
	
	public void attach(ComputerParts equip) {
		if (equip != null) {
			parts.add(equip);
		}
	}
	
	public void detach(ComputerParts equip) {
		if (equip != null) {
			parts.remove(equip);
		}
	}
	
	public Iterator<ComputerParts>elements(){
		return parts.iterator();
	}
	
	public int getSize() {
		return parts.size();
	}

}
